package reflect;

import annotation.AutoRunClass;
import annotation.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入类名:");
        String classname = scanner.nextLine();
        Class cls = Class.forName(classname);
        Object object = cls.newInstance();
        boolean mark = cls.isAnnotationPresent(AutoRunClass.class);
        if (mark){
            Method[] methods = cls.getDeclaredMethods();
            for (Method m:methods){
                if (m.isAnnotationPresent(AutoRunMethod.class)){
                    System.out.println(m.getName());
                    m.invoke(object);
                }
            }
        }else {
            System.out.println(cls.getSimpleName()+"类没有被注解");
        }
    }
}
